﻿$(function () {
    var corpUserGuid = $("#hdnCorpUserGuid").val();
    var snapGuid = $("#hdnSnapGuid").val();
    var snapState = $("#hdnSnapState").val();
    var snapKind = $("#hdnSnapKind").val();

    //修改操作，从历史记录中获取数据
    $.getJSON("../../Handlers/EnterpriseCorpInfoHandler.ashx", { "action": "GetSnapInfo", "corpUserGuid": corpUserGuid, "snapKind": "1000", "rand": Math.random() }, function (data) {
        if (data) {
            $("#hdnSnapGuid").val(data.SnapGuid);
            $("#hdnID").val(data.ID);
            var companyInfo = data.SnapData;
            SetControlVal("CompanyinfoKH", companyInfo);
            $("#lblCorpName").text($("#txtCorpName").val());
        }
        else {
            //添加数据
            $.getJSON("../../Handlers/EnterpriseCorpInfoHandler.ashx", { "action": "KaoheGetCompanyInfo", "corpUserGuid": corpUserGuid, "snapGuid": snapGuid, "rand": Math.random() }, function (data) {
                if (data) {
                    SetControlVal("CompanyinfoKH", data);
                    switch ($("#txtClassID").val()) {
                        case "2501":
                        case "25010":
                            $("#txtClassID").val("施工企业");
                            break;
                        case "2506":
                        case "25060":
                            $("#txtClassID").val("装饰装修企业");
                            break;
                        case "2301":
                        case "23010":
                            $("#txtClassID").val("门窗企业");
                            break;
                        case "30":
                        case "300":
                            $("#txtClassID").val("商砼企业");
                            break;
                        default:
                            $("#txtClassID").val("施工企业");
                            break;
                    }
                    //var companyInfo = data.CompanyInfoKH;
                    //SetControlVal("CompanyinfoKH", companyInfo);
                    //var capitalBusinessInfo = data.CapitalBusinessKH;
                    //SetControlVal("CapitalBusinessKH", capitalBusinessInfo);
                    //                var projectAchieveMentKH = data.ProjectAchieveMentKH;
                    //                SetControlVal("ProjectAchieveMentKH", projectAchieveMentKH);
                }
            }
    );
        }
    }
    );


    ////资金及经营情况 保存事件
    $("#btnCapitalSave").click(SaveCompanyAttchInfo);
    $("#btnProjectAchieveMentSave").click(SaveCompanyAttchInfo);
    InitControlState();
}
);

function SaveCompanyAttchInfo() {
    var _corpUserGuid = $("#hdnCorpUserGuid").val();
    var dataValid = CheckControlValid("btnCapitalSave");
    if (!dataValid) {
        return false;
    }
    var capitalInfo = GetData("btnCapitalSave");
    var pAchieveInfo = GetData("btnProjectAchieveMentSave");
    ////保存资金及经营情况
    $.post(
        "../Handlers/EnterpriseCorpInfoHandler.ashx",
         { "action": "CompanyAttchInfoKHEdit", "corpUserGuid": _corpUserGuid, "capitalInfo": capitalInfo, "pAchieveInfo": pAchieveInfo },
         function (data) {
             if (data) {
                 alert(data.Message);
             }
         }, "json"
        );
}

function InitControlState() {
    var snapState = $("#hdnSnapState").val();
    if (snapState == "0") {
        //资金及经营情况、工程业绩不可编辑
        $("input").attr("disabled", "disabled");
    }
}

//日期格式转化
function DateFormatConvert(date) {
    var dateStr = date;
    if (typeof date == "object") {
        dateStr = date.toLocaleString();
    } else if (typeof date == "string") {
        dateStr = date;
    }
    return dateStr.replace(/^([\d-]+)T([\d:]+).+$/, "$1 $2");
}
////修改企业开户行
function CompanyBankEdit() {
    if (!CheckData()) {
        return false;
    }
    var parmer = {};
    parmer.action = "BankEdit";
    parmer.corpGuid = $("#hdnCorpUserGuid").val();
    parmer.areaCode = $("#hdAreaCode").val();
    parmer.bankName = $("#txtBankName").val();
    parmer.bankAccNo = $("#txtBankAccNo").val();
    parmer.rand = Math.random();
    $.getJSON("../Handlers/KaoHeHandler.ashx", parmer, function (data) {

        OpenAlert(data.Message);
    });
}
////开户行验证
function CheckData() {
    if ($.trim($("#txtBankName").val()) == "") {
        alert("开户行名称不能为空！");
        return false;
    }
    if ($.trim($("#txtBankAccNo").val()) == "") {
        alert("开户行账号不能为空！");
        return false;
    }
    return true;
}

